#include<iostream>
#include<future>
#include<atomic>
#include<thread>
int main(int n,char **agv)
{
    //复刻前面的不线程安全代码
    using std::cout,std::endl,std::atomic,std::thread;
    thread thpool[1000];
    int target=0;//只需要修改这里就会变成线程安全的函数。atomic<int>
    auto set =[&target](int n)
    {
        for (size_t i = 0; i < n; i++)
        {
            target++;
            std::this_thread::sleep_for(std::chrono::milliseconds(2));
        }
    };

    for(auto &e:thpool) e=thread(set,1000);
    for(auto &e:thpool) e.join();
    cout<<target<<endl;
    return 0;
}